﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DisposeTest
{
    public class Parent
    {
        public event EventHandler Event;

        private Child m_Child;

        public void CreateChild()
        {
            m_Child = new Child(this);
        }

        public void DestroyChild()
        {
            m_Child = null;
        }
    }

    public class Child
    {
        public Child(Parent parent)
        {
            parent.Event += this.Handler;
        }

        private void Handler(object sender, EventArgs args) { }

        ~Child() { Console.WriteLine("disposed"); }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var parent = new Parent();
            parent.CreateChild();
            parent.DestroyChild();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }
}
